<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/** @var \yii\web\View $this */
/** @var \builder\form\FormBuilder $context 当前表单组件实例 */
/** @var array $rootLayout 根布局 */
/** @var array $body 表单组内容 */
/** @var string $requiredStyle 必填项标记风格 */
/** @var array $footerLayout 表单尾部布局 */
/** @var array $footerBtn 表单尾部按钮 */
/** @var bool $footerFixed 是否固定表单底部 */

$context = $this->context;
?>

<div id="__YM2_BUILDER_ID__<?= $context->id ?>" class="ym2-form-ui card border-0 <?= $rootLayout['class'] ?>" style="<?= $rootLayout['style'] ?>" ng-controller="ym2.ctrl.<?= $context->id ?>"<?= $rootLayout['attribute'] ?>>
    <div class="card-body">
        <!--开始表单-->
        <?= $context->beginForm() ?>

        <form class="card-body p-0" novalidate>
            <div class="row">
                <!--表单分组-->
<?php foreach ($body as $groupField => $options): ?>
<?php
$showCardHeader = !empty($options['title']) || !empty($options['comment']);
?>
                <div class="col-md-<?= $options['layout'] ?> <?= $options['class'] ?>"<?= $options['attribute'] ?> style="<?= $options['style'] ?>">
                    <div class="layui-card shadow-none<?= $showCardHeader ? ' layui-border rounded-12' : '' ?>">
                        <!--分组名称-->
<?php if ($showCardHeader): ?>
                        <div class="layui-card-header layui-card-header-light">
<?php if (!empty($options['title'])): ?>
                            <span class="f15 font-weight-bold"><?= $options['title'] ?></span>
<?php endif; ?>
<?php if (!empty($options['comment'])): ?>
                            <!--分组注释-->
                            <comment class="text-comment pl-1 f12"><?= $options['comment'] ?></comment>
<?php endif; ?>
                        </div>
<?php endif; ?>
                        <!--表单控件-->
<?php if (!empty($options['controls'])): ?>
                        <div class="layui-card-body row<?= $showCardHeader ? '' : ' py-0' ?>">
                        <?= $this->renderPhpFile(
                            __DIR__ . '/tpl/view.form.control.php',
                            [
                                'controlItems' => $options['controls'],
                                'requiredStyle' => $requiredStyle,
                                'groupField' => $groupField,
                            ]) ?>
                        </div>
<?php endif; ?>
                    </div>
                </div>
<?php endforeach; ?>
            </div>
            <!--结束表单-->
            <?= $context->endForm() ?>

<?php if (!empty($footerBtn)): ?>
<?php if ($footerFixed): ?>
            <div class="form-footer-placeholder"></div>
<?php endif; ?>
            <div class="card-body <?= $footerFixed ? 'form-footer-fixed' : 'pb-0' ?> <?= $footerLayout['class'] ?>" style="<?= $footerLayout['style'] ?>"<?= $footerLayout['attribute'] ?>>
<?php foreach ($footerBtn as $type => $item): ?>
<?php switch ((string)$type): case 'submit': //提交按钮 ?>
                <button class="layui-btn layui-btn-sm px-15 layui-btn-theme ym2-form-submit-ui" ng-click="formSubmit()"><?= $item['title'] ?></button>
<?php break; case 'reset': //重置按钮 ?>
                <button type="button" class="layui-btn layui-btn-sm px-15 layui-btn-gray ym2-form-reset-ui" ng-click="formReset()"><?= $item['title'] ?></button>
<?php break; case 'close': //关闭按钮 ?>
                <button type="button" class="layui-btn layui-btn-sm px-15 layui-btn-primary ym2-form-close-ui" ng-click="formClose()"><?= $item['title'] ?></button>
<?php break; case 'back': //返回按钮 ?>
                <button type="button" class="layui-btn layui-btn-sm px-15 layui-btn-primary ym2-form-back-ui" ng-click="formBack()"><?= $item['title'] ?></button>
<?php break; default: //额外的按钮 ?>
                <?= $item['content'] ?>
<?php endswitch; ?>
<?php endforeach; ?>
            </div>
<?php endif; ?>

        </form>
    </div>
</div>
